import * as actions from '../actions/index';

// 页面初始化数据
export const initialState = {
  repositoryDeployKeys: [],
  authorizedDeployKeys: [],
  isLoadingTable: true,
  isIPLoading: true,
  ip_whitelist_data: {},
};
const defaultAction = {
  type: 'doNothing',
};

export default function index(state = initialState, action = defaultAction) {
  switch (action.type) {
    case actions.UPDATE_DATA:
      return { ...state, ...action.data };
    case actions.RECEIVE_REPOSITORY_DEPLOY_KEYS:
      return { ...state, repositoryDeployKeys: action.data.list, isLoadingTable: false };
    case actions.RECEIVE_AUTHORIZED_DEPLOY_KEYS:
      return { ...state, authorizedDeployKeys: action.data.list };
    case actions.RECEIVE_IP_WHITE_CHECK:
      return { ...state, ip_whitelist_data: action.data, isIPLoading: false };
    default:
      return state;
  }
}
